package com.masterclient.app.modules.aftersale;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.eoner.baselibrary.bean.address.AddressBean;
import com.eoner.baselibrary.bean.address.AddressMessage;
import com.eoner.baselibrary.bean.aftersale.NewRefundDetailsBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.BaseFragment;
import com.masterclient.app.R;
import com.masterclient.app.base.ProgressLoginDialog;
import com.masterclient.app.businessmodule.minemodule.address.ChangeAddressActivity;
import com.masterclient.app.modules.aftersale.contract.RefundDetailsContract;
import com.masterclient.app.modules.aftersale.contract.RefundDetailsPresenter;
import com.masterclient.app.modules.order.utils.ModelAdapterUtil;
import com.masterclient.app.widget.PriceIntegralLayout;

import java.io.Serializable;
import java.util.Objects;

import butterknife.BindView;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

@Route(path = AroutePath.REFUND_DETAILS_FRAGMENT)
public class RefundDetailsFragment extends BaseFragment<RefundDetailsPresenter> implements RefundDetailsContract.View {

    @BindView(R.id.tv_page_title)
    TextView tvPageTitle;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_title_tips)
    TextView tvTitleTips;
    @BindView(R.id.view_head)
    LinearLayout viewHead;
    @BindView(R.id.view_address)
    View viewAddress;
    @BindView(R.id.tv_address_des)
    TextView tvAddressDes;
    @BindView(R.id.tv_addressee)
    TextView tvAddressee;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_look_details)
    TextView tvLookDetails;
    @BindView(R.id.view_after_sale)
    View viewAfterSale;
    @BindView(R.id.ll_return_good)
    View llReturnGood;
    @BindView(R.id.ll_return_money)
    View llReturnMoney;
    @BindView(R.id.iv1)
    ImageView iv1;
    @BindView(R.id.iv2)
    ImageView iv2;
    @BindView(R.id.iv3)
    ImageView iv3;
    @BindView(R.id.iv4)
    ImageView iv4;
    @BindView(R.id.iv5)
    ImageView iv5;
    @BindView(R.id.iv6)
    ImageView iv6;
    @BindView(R.id.iv7)
    ImageView iv7;
    @BindView(R.id.iv8)
    ImageView iv8;
    @BindView(R.id.view_product)
    LinearLayout viewProduct;
    @BindView(R.id.view_product_bottom)
    View viewProductBottom;
    @BindView(R.id.tv_refund_price)
    PriceIntegralLayout tvRefundPrice;
    @BindView(R.id.view_customer)
    LinearLayout viewCustomer;
    @BindView(R.id.view_refund)
    LinearLayout viewRefund;
    @BindView(R.id.view_image)
    View viewImage;
    @BindView(R.id.gridLayout)
    GridLayout gridLayout;
    @BindView(R.id.view_bottom)
    View viewBottom;
    @BindView(R.id.tv_look_logistics)
    TextView tvLookLogistics;
    @BindView(R.id.tv_look)
    TextView tvLook;
    @BindView(R.id.tv_update)
    TextView tvUpdate;

    @Autowired(name = "refundNo")
    String refundNo;
    @Autowired(name = "order_id")
    String orderId;
    @Autowired(name = "order_product_id")
    String orderProductId;

    private AfterSaleDialog afterSaleDialog;
    private ProgressLoginDialog progressLoginDialog;
    private NewRefundDetailsBean mData;

    public static RefundDetailsFragment newInstance() {
        return new RefundDetailsFragment();
    }

    @Override
    protected View getRootView(LayoutInflater inflater) {
        setFullScreenAndTransparent(getActivity());
        return inflater.inflate(R.layout.fragment_refund_details, null);
    }

    @Override
    protected void initOnlyOnce() {
        super.initOnlyOnce();
        ARouter.getInstance().inject(this);

        progressLoginDialog = new ProgressLoginDialog(getActivity());
    }

    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getRefundDetailsInfo(refundNo,orderId,orderProductId);
    }

    @OnClick({R.id.rl_back, R.id.tv_look_details})
    void onClick(View view) {
        int id = view.getId();
        if (id == R.id.rl_back) {
            Objects.requireNonNull(getActivity()).finish();
        } else if (id == R.id.tv_look_details) {
            if (mData != null && mData.statusProgress != null && mData.statusProgress.size() > 1) {
                Intent intent = new Intent(mContext, ReturnProgressActivity.class);
                intent.putExtra("list", (Serializable) mData.statusTip);
                intent.putExtra("state", mData.statusProgress.get(1));
                startActivity(intent);
            }
        }
    }

    @Override
    public void showRefundDetailsInfo(NewRefundDetailsBean bean) {
        if (bean != null) {

            mData = bean;
            //页面标题
            if ("0".equals(bean.refundType)) {
                tvPageTitle.setText("退款详情");
            } else {
                tvPageTitle.setText("退货退款详情");
            }

            //头部信息
            if (bean.topArr != null && !TextUtils.isEmpty(bean.topArr.title)) {
                tvTitle.setText(bean.topArr.title);
                tvTitle.setVisibility(View.VISIBLE);
            } else {
                tvTitle.setVisibility(View.GONE);
            }
            if (bean.topArr != null && !TextUtils.isEmpty(bean.topArr.description)) {
                tvTitleTips.setText(bean.topArr.description);
                tvTitleTips.setVisibility(View.VISIBLE);
            } else {
                tvTitleTips.setVisibility(View.GONE);
            }

            //描述信息
            if (bean.remarkArr != null && bean.remarkArr.size() > 0) {
                viewHead.removeAllViews();
                for (int i = 0; i < bean.remarkArr.size(); i++) {
                    NewRefundDetailsBean.RemarkArrBean remarkArrBean = bean.remarkArr.get(i);
                    View view = View.inflate(mContext, R.layout.item_refund_head_info, null);
                    TextView tvReason = view.findViewById(R.id.tv_reason);

                    tvReason.setText(remarkArrBean.text);
                    tvReason.setTextColor(Color.parseColor(remarkArrBean.color));
                    viewHead.addView(view);
                }
                viewHead.setVisibility(View.VISIBLE);
            } else {
                viewHead.setVisibility(View.GONE);
            }

            //收货信息
            if (bean.sellerAddress != null && !TextUtils.isEmpty(bean.sellerAddress.address)) {
                tvAddressDes.setText(bean.sellerAddress.title);
                tvAddressee.setText(String.format("收件人：%s%s", bean.sellerAddress.fullName, bean.sellerAddress.mobile));
                tvAddress.setText(String.format("退货地址：%s", bean.sellerAddress.address));
                viewAddress.setVisibility(View.VISIBLE);
            } else {
                viewAddress.setVisibility(View.GONE);
            }

            //售后进度信息
            doAfterSaleStatus();

            //商品信息
            if (bean.products != null && bean.products.size() > 0) {
                viewProduct.removeAllViews();
                for (int i = 0; i < bean.products.size(); i++) {
                    NewRefundDetailsBean.ProductBean productBean = bean.products.get(i);
                    View view = View.inflate(mContext, R.layout.item_product_info, null);
                    ImageView ivGood = view.findViewById(R.id.iv_good);
                    TextView tvTitle = view.findViewById(R.id.tv_goods_title);
                    TextView tvSku = view.findViewById(R.id.tv_skus);
                    PriceIntegralLayout llPrice = view.findViewById(R.id.ll_price);
                    TextView tvNum = view.findViewById(R.id.tv_num);

                    tvTitle.setText(productBean.name);
                    tvNum.setText(String.format("×%s", productBean.qtyOrdered));
                    tvSku.setText(productBean.attributeDesc);
                    llPrice.setData("", productBean.amount);
                    ViewTransformUtil.glideImageView(mContext, productBean.image, ivGood,
                            new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0),
                            R.mipmap.defaults, ScreenUtils.dp2px(100), ScreenUtils.dp2px(100));
                    viewProduct.addView(view);
                }
                if (!TextUtils.isEmpty(bean.refundAmount)) {
                    tvRefundPrice.setData("", bean.refundAmount);
                }
                viewProduct.setVisibility(View.VISIBLE);
                viewProductBottom.setVisibility(View.VISIBLE);
            } else {
                viewProduct.setVisibility(View.GONE);
                viewProductBottom.setVisibility(View.GONE);
            }

            //用户信息
            if (bean.orderInfo != null && bean.orderInfo.size() > 0) {
                viewCustomer.removeAllViews();
                for (int i = 0; i < bean.orderInfo.size(); i++) {
                    NewRefundDetailsBean.CustomerInfoBean customerInfoBean = bean.orderInfo.get(i);
                    View view = View.inflate(mContext, R.layout.item_customer_info, null);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvContent = view.findViewById(R.id.tv_content);
                    TextView tvCopy = view.findViewById(R.id.tv_copy);

                    tvName.setText(customerInfoBean.label);
                    tvContent.setText(customerInfoBean.text);
                    tvCopy.setVisibility(customerInfoBean.copyable ? View.VISIBLE : View.GONE);
                    if (customerInfoBean.copyable) {
                        tvCopy.setOnClickListener(v -> copyTxt(customerInfoBean.text));
                    }
                    viewCustomer.addView(view);
                }
                viewCustomer.setVisibility(View.VISIBLE);
            } else {
                viewCustomer.setVisibility(View.GONE);
            }

            //退款信息
            if (bean.contentArr != null && bean.contentArr.size() > 0) {
                viewRefund.removeAllViews();
                for (int i = 0; i < bean.contentArr.size(); i++) {
                    NewRefundDetailsBean.CustomerInfoBean customerInfoBean = bean.contentArr.get(i);
                    View view = View.inflate(mContext, R.layout.item_customer_info, null);
                    TextView tvName = view.findViewById(R.id.tv_name);
                    TextView tvContent = view.findViewById(R.id.tv_content);
                    TextView tvCopy = view.findViewById(R.id.tv_copy);

                    tvName.setText(customerInfoBean.label);
                    tvContent.setText(customerInfoBean.text);
                    tvCopy.setVisibility(customerInfoBean.copyable ? View.VISIBLE : View.GONE);
                    if (customerInfoBean.copyable) {
                        tvCopy.setOnClickListener(v -> copyTxt(customerInfoBean.text));
                    }
                    viewRefund.addView(view);
                }
                viewRefund.setVisibility(View.VISIBLE);
            } else {
                viewRefund.setVisibility(View.GONE);
            }

            //上传图片信息
            if (bean.images != null && bean.images.size() > 0) {
                gridLayout.removeAllViews();
                viewImage.setVisibility(View.VISIBLE);
                for (String url : bean.images) {
                    int width = (ScreenUtils.getScreenWidth() - ScreenUtils.dp2px(71)) / 4;
                    ImageView imageView = new ImageView(mContext);
                    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    GridLayout.LayoutParams params = new GridLayout.LayoutParams(new ViewGroup.LayoutParams(width, width));
                    params.setMargins(0, ScreenUtils.dp2px(13), ScreenUtils.dp2px(13), 0);
                    imageView.setLayoutParams(params);
                    ViewTransformUtil.glideImageView(getActivity(), url, imageView,
                            new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0),
                            R.mipmap.defaults, width, ScreenUtils.dp2px(width));
                    gridLayout.addView(imageView);
                }
            } else {
                viewImage.setVisibility(View.GONE);
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) viewRefund.getLayoutParams();
                params.bottomMargin = ScreenUtils.dp2px(100);
                viewRefund.setLayoutParams(params);
            }

            //底部按钮显示操作
            doBottomBtnStatus();
        }
    }

    @Override
    public void refundDealSuccess(String msg) {
        progressLoginDialog.dismiss();
        if (afterSaleDialog != null && afterSaleDialog.isShowing()) {
            afterSaleDialog.dismiss();
        }
        mPresenter.getRefundDetailsInfo(refundNo,orderId,orderProductId);
        ToastUtil.showToast("成功！");
    }

    @Override
    public void showFail(String msg) {
        progressLoginDialog.dismiss();
        ToastUtil.showToast(msg);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (resultCode == 103) {//地址
            AddressBean.DataBean.ShItemsBean itemsBean = (AddressBean.DataBean.ShItemsBean) intent.getSerializableExtra("default_address");
            AddressMessage addressMessage = ModelAdapterUtil.addressMessageConvert(itemsBean);
            afterSaleDialog.updateAddress(addressMessage.getAddress_id(), addressMessage.getFull_name(), addressMessage.getMobile(),
                    addressMessage.getProvince() + addressMessage.getCity() + addressMessage.getArea() + addressMessage.getAddress());
        }
    }

    private ClipboardManager cm;

    private void copyTxt(String content) {
        if (cm == null) {
            cm = (ClipboardManager) Objects.requireNonNull(getActivity()).getSystemService(Context.CLIPBOARD_SERVICE);
        }
        cm.setPrimaryClip(ClipData.newPlainText(null, content));
        showToast("已复制到粘贴板");
    }

    /**
     * 处理售后状态显示
     */
    private void doAfterSaleStatus(){
        String position = "";
        String status = "";
        if (mData.statusProgress != null && mData.statusProgress.size() == 2){
            position = mData.statusProgress.get(0);
            status = mData.statusProgress.get(1);
        }
        if ("0".equals(mData.refundType) || "3".equals(mData.refundType)){
            llReturnGood.setVisibility(View.GONE);
            llReturnMoney.setVisibility(View.VISIBLE);
            if ("0".equals(position)){
                if ("0".equals(status)){
                    iv6.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                    iv7.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv8.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }else if ("1".equals(status)){
                    iv6.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv7.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv8.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }
            }else if ("1".equals(position)){
                if ("0".equals(status)){
                    iv6.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv7.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                    iv8.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }else if ("1".equals(status)){
                    iv6.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv7.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv8.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }
            }else if ("2".equals(position)){
                if ("0".equals(status)){
                    iv6.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv7.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv8.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                }else if ("1".equals(status)){
                    iv6.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv7.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv8.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                }
            }
        }else {
            llReturnGood.setVisibility(View.VISIBLE);
            llReturnMoney.setVisibility(View.GONE);
            if ("0".equals(position)){
                if ("0".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }else if ("1".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }
            }else if ("1".equals(position)){
                if ("0".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }else if ("1".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }
            }else if ("2".equals(position)){
                if ("0".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }else if ("1".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }
            }else if ("3".equals(position)){
                if ("0".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }else if ("1".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_undone);
                }
            }else if ("4".equals(position)){
                if ("0".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_error);
                }else if ("1".equals(status)){
                    iv1.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv2.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv3.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv4.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                    iv5.setImageResource(R.mipmap.icon_dealer_aftersale_done);
                }
            }
        }
    }

    /**
     * 处理底部视图根据状态显示按钮
     */
    private void doBottomBtnStatus() {
        boolean isShowLeft = false;
        boolean isShowMiddle = false;
        boolean isShowRight = false;
        if (mData.buttonArr != null) {
            //仅退款审核拒绝、仅退款确认退款、退货退款审核拒绝、退货退款拒绝收货、退货退款确认退款
            if ("1".equals(mData.buttonArr.moneyRefuseApproveBtn) || "1".equals(mData.buttonArr.moneyPayConfirmBtn) ||
                    "1".equals(mData.buttonArr.productRefuseApproveBtn) || "1".equals(mData.buttonArr.productReceiveRefuseBtn)
                    || "1".equals(mData.buttonArr.productPayConfirmBtn)) {
                isShowMiddle = true;
                String refuseStr = "";
                boolean isRefuse = true;
                if ("1".equals(mData.buttonArr.moneyRefuseApproveBtn)) {
                    refuseStr = "审核拒绝";
                    isRefuse = true;
                }
                if ("1".equals(mData.buttonArr.moneyPayConfirmBtn)) {
                    refuseStr = "确认退款";
                    isRefuse = false;
                }
                if ("1".equals(mData.buttonArr.productRefuseApproveBtn)) {
                    refuseStr = "审核拒绝";
                    isRefuse = true;
                }
                if ("1".equals(mData.buttonArr.productReceiveRefuseBtn)) {
                    refuseStr = "拒绝收货";
                    isRefuse = true;
                }
                if ("1".equals(mData.buttonArr.productPayConfirmBtn)) {
                    refuseStr = "确认退款";
                    isRefuse = false;
                }
                tvLook.setText(refuseStr);
                tvLook.setVisibility(View.VISIBLE);
                boolean finalIsRefuse = isRefuse;
                tvLook.setOnClickListener(v -> {
                    initClickStatus();
                    if ("1".equals(mData.buttonArr.moneyRefuseApproveBtn)) {
                        mData.buttonArr.isClickMoneyRefuseApproveBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.moneyPayConfirmBtn)) {
                        mData.buttonArr.isClickMoneyPayConfirmBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productRefuseApproveBtn)) {
                        mData.buttonArr.isClickProductRefuseApproveBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productReceiveRefuseBtn)) {
                        mData.buttonArr.isClickProductReceiveRefuseBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productPayConfirmBtn)) {
                        mData.buttonArr.isClickProductPayConfirmBtn = true;
                    }
                    afterSaleDialog = new AfterSaleDialog(Objects.requireNonNull(getActivity()), mData,
                            finalIsRefuse, new AfterSaleDialog.OnClickAfterSaleListener() {
                        @Override
                        public void clickUpdateAddress() {

                        }

                        @Override
                        public void clickConfirm(String refund_no, String operate, String operateData) {
                            progressLoginDialog.show();
                            progressLoginDialog.setDesc("正在加载...");
                            mPresenter.refundDeal(refund_no, operate, operateData);
                        }
                    });
                    afterSaleDialog.show();
                });
            } else {
                tvLook.setVisibility(View.GONE);
            }

            //仅退款审核通过、仅退款拒绝退款、退货退款审核通过、退货退款用户协商取消、退货退款确认收货、退货退款拒绝退款、被提货关联仅退款审核通过、保管退货退款审核通过
            if ("1".equals(mData.buttonArr.moneyPassApproveBtn) || "1".equals(mData.buttonArr.moneyPayRefuseBtn) ||
                    "1".equals(mData.buttonArr.productPassApproveBtn) || "1".equals(mData.buttonArr.productWaitShipmentCancelBtn) ||
                    "1".equals(mData.buttonArr.productReceiveConfirmBtn) || "1".equals(mData.buttonArr.productPayRefuseBtn) ||
                    "1".equals(mData.buttonArr.moneyBehalfPassApproveBtn) || "1".equals(mData.buttonArr.productCustodyPassApproveBtn)) {

                isShowRight = true;
                String refuseStr = "";
                boolean isRefuse = true;
                if ("1".equals(mData.buttonArr.moneyPassApproveBtn)) {
                    refuseStr = "审核通过";
                    isRefuse = false;
                }
                if ("1".equals(mData.buttonArr.moneyPayRefuseBtn)) {
                    refuseStr = "拒绝退款";
                    isRefuse = true;
                }
                if ("1".equals(mData.buttonArr.productPassApproveBtn)) {
                    refuseStr = "审核通过";
                    isRefuse = false;
                }
                if ("1".equals(mData.buttonArr.productWaitShipmentCancelBtn)) {
                    refuseStr = "用户协商取消";
                    isRefuse = true;
                }
                if ("1".equals(mData.buttonArr.productReceiveConfirmBtn)) {
                    refuseStr = "确认收货";
                    isRefuse = false;
                }
                if ("1".equals(mData.buttonArr.productPayRefuseBtn)) {
                    refuseStr = "拒绝退款";
                    isRefuse = true;
                }
                if ("1".equals(mData.buttonArr.moneyBehalfPassApproveBtn)) {
                    refuseStr = "审核通过";
                    isRefuse = false;
                }
                if ("1".equals(mData.buttonArr.productCustodyPassApproveBtn)) {
                    refuseStr = "审核通过";
                    isRefuse = false;
                }
                tvUpdate.setText(refuseStr);
                tvUpdate.setVisibility(View.VISIBLE);
                boolean finalIsRefuse = isRefuse;
                tvUpdate.setOnClickListener(v -> {
                    initClickStatus();
                    if ("1".equals(mData.buttonArr.moneyPassApproveBtn)) {
                        mData.buttonArr.isClickMoneyPassApproveBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.moneyPayRefuseBtn)) {
                        mData.buttonArr.isClickMoneyPayRefuseBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productPassApproveBtn)) {
                        mData.buttonArr.isClickProductPassApproveBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productWaitShipmentCancelBtn)) {
                        mData.buttonArr.isClickProductWaitShipmentCancelBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productReceiveConfirmBtn)) {
                        mData.buttonArr.isClickProductReceiveConfirmBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productPayRefuseBtn)) {
                        mData.buttonArr.isClickProductPayRefuseBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.moneyBehalfPassApproveBtn)) {
                        mData.buttonArr.isClickMoneyBehalfPassApproveBtn = true;
                    }
                    if ("1".equals(mData.buttonArr.productCustodyPassApproveBtn)) {
                        mData.buttonArr.isClickProductCustodyPassApproveBtn = true;
                    }
                    afterSaleDialog = new AfterSaleDialog(Objects.requireNonNull(getActivity()), mData,
                            finalIsRefuse, new AfterSaleDialog.OnClickAfterSaleListener() {
                        @Override
                        public void clickUpdateAddress() {
                            if ("1".equals(mData.buttonArr.productPassApproveBtn)) {
                                Intent intent = new Intent(getActivity(),ChangeAddressActivity.class);
                                intent.putExtra("isPurchase","1");
                                startActivityForResult(intent, 100);
                            }
                        }

                        @Override
                        public void clickConfirm(String refund_no, String operate, String operateData) {
                            progressLoginDialog.show();
                            progressLoginDialog.setDesc("正在加载...");
                            mPresenter.refundDeal(refund_no, operate, operateData);
                        }
                    });
                    afterSaleDialog.show();
                });
            } else {
                tvUpdate.setVisibility(View.GONE);
            }

            //退货退款查看物流
            if ("1".equals(mData.buttonArr.productViewShipmentBtn)) {
                isShowLeft = true;
                tvLookLogistics.setText("查看物流");
                tvLookLogistics.setVisibility(View.VISIBLE);
                tvLookLogistics.setOnClickListener(v -> {
                    Intent intent = new Intent(getActivity(), LogistInfoActivity.class);
                    if ("2".equals(mData.bizType)){
                        intent.putExtra("order_id", mData.id);
                    }else {
                        intent.putExtra("order_id", mData.orderId);
                    }
                    intent.putExtra("track_no", mData.trackNo);
                    intent.putExtra("biz_type", mData.bizType);
                    Objects.requireNonNull(getActivity()).startActivity(intent);
                });
            } else {
                tvLookLogistics.setVisibility(View.GONE);
            }

            //底部视图
            if (isShowLeft || isShowMiddle || isShowRight) {
                viewBottom.setVisibility(View.VISIBLE);
            } else {
                viewBottom.setVisibility(View.GONE);
            }
        }
    }

    /**
     * 初始化底部视图根据状态显示按钮
     */
    private void initClickStatus() {
        mData.buttonArr.isClickMoneyRefuseApproveBtn = false;
        mData.buttonArr.isClickMoneyPayConfirmBtn = false;
        mData.buttonArr.isClickProductRefuseApproveBtn = false;
        mData.buttonArr.isClickProductReceiveRefuseBtn = false;
        mData.buttonArr.isClickProductPayConfirmBtn = false;
        mData.buttonArr.isClickMoneyPassApproveBtn = false;
        mData.buttonArr.isClickMoneyPayRefuseBtn = false;
        mData.buttonArr.isClickProductPassApproveBtn = false;
        mData.buttonArr.isClickProductWaitShipmentCancelBtn = false;
        mData.buttonArr.isClickProductReceiveConfirmBtn = false;
        mData.buttonArr.isClickProductPayRefuseBtn = false;
        mData.buttonArr.isClickMoneyBehalfPassApproveBtn = false;
        mData.buttonArr.isClickProductCustodyPassApproveBtn = false;
    }
}
